package goover.unit06;

public class RunnableDemo07 {
    public static void main(String[] args){
        Test04 t = new Test04();
        Thread t1 = new Thread(t,"窗口1：");
        Thread t2 = new Thread(t,"窗口2：");
        t1.start();
        t2.start();
    }
}
class Test04 implements Runnable{
    private int temp = 10;
    @Override
    public void run() {
        while (true){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            sum();
        }
    }
    private synchronized void sum(){
        if(temp > 0){
            System.out.println(Thread.currentThread().getName() + "票数:" + temp--);
        }
    }
}